package com.csair.platform.cit.service.controller;

import com.alibaba.fastjson.JSON;
import com.csair.invoice.common.base.vo.JsonResult;
import com.csair.platform.cit.facade.CitZcjszjkcmxbApi;
import com.csair.platform.cit.facade.model.citzcjszjkcmx.CitZcjszjkcmxbRequest;
import com.csair.platform.cit.facade.model.citzcjszjkcmx.CitZcjszjkcmxbVo;
import com.csair.platform.cit.service.biz.ICitZcjszjkcmxbService;
import com.csair.platform.cit.service.core.CheckDataPermission;
import com.csair.platform.usercenter.facade.model.user.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author zhengxincheng
 */
@Api(tags = "资产加速折旧、摊销（扣除）优惠控制类")
@Slf4j
@RestController
public class CitZcjszjkcmxbController extends BaseController implements CitZcjszjkcmxbApi {

    @Autowired
    ICitZcjszjkcmxbService iCitZcjszjkcmxbService;

    @CheckDataPermission
    @ApiOperation(value = "企业所得税-保存")
    @Override
    public JsonResult save(@RequestBody CitZcjszjkcmxbRequest czs) {
        log.info("《资产加速折旧、摊销（扣除）优惠明细表》 数据保存:{}", JSON.toJSONString(czs));

        UserVo user = getCurrentUser();

        czs.getData().forEach(i ->{
            i.setLastTime(new Date());
            i.setCreateTime(new Date());
            i.setCreateBy(user.getCreateBy());
            i.setNsrsbh(czs.getNsrsbh());
            i.setSkssqq(czs.getSkssqq());
            i.setSkssqz(czs.getSkssqz());
        });
        iCitZcjszjkcmxbService.save(czs);
        return JsonResult.success();
    }

    @CheckDataPermission
    @ApiOperation(value = "企业所得税-根据税号查询")
    @Override
    public JsonResult query(@RequestBody CitZcjszjkcmxbRequest czs) {
        log.info("《资产加速折旧、摊销（扣除）优惠明细表》 数据查询:{}", JSON.toJSONString(czs));
        List<CitZcjszjkcmxbVo> data = iCitZcjszjkcmxbService.query(czs.getNsrsbh(),czs.getSkssqq(),czs.getSkssqz());
        return JsonResult.success(data);
    }
}
